import "../Base/UiBase/TC" as TC

import Cpp.Request 1.0 as Request
import FunctionalItem 1.0

RegisterForm {
    id: root
    signal loginClicked

    phoneInput.onTextChanged: {
        if (phoneInput.acceptableInput)
            phoneValidtor.phoneExist(phoneInput.text)
    }

    toLoginPageButton.onClicked: {
        loginClicked()
    }

    registerButton.onClicked: {
        if (phoneInput.acceptableInput
                && phoneValidtor.status === Request.RegisterValidator.Ok
                && passwordInput.text === verifyPasswordInput.text)
            registerRequest.registerWithPhone(phoneInput.text,
                                              passwordInput.text)
    }

    getCaptchaButton.onClicked: {
        ;
    }

    phoneErrorIcon.visible: !(phoneInput.acceptableInput
                              && phoneValidtor.status === Request.RegisterValidator.Ok)

    FocusSwitch {
        id: focusSwitch
        sequence: [phoneInput, captchaInput, passwordInput, verifyPasswordInput]
        accept: registerButton
    }

    Request.RegisterValidator {
        id: phoneValidtor
    }

    Request.Register {
        id: registerRequest
        onOk: {
            loginRequest.login(phoneInput.text, passwordInput.text)
            //            messageBox.show(qsTr("注册成功"))
        }
    }
    Request.Login {
        id: loginRequest
    }
}
